﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.LightProbes
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine.Bindings;
using UnityEngine.Rendering;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Stores light probe data for all currently loaded Scenes.</para>
  /// </summary>
  [NativeHeader("Runtime/Export/Graphics/Graphics.bindings.h")]
  [StructLayout(LayoutKind.Sequential)]
  public sealed class LightProbes : Object
  {
    private LightProbes()
    {
    }

    public static event Action tetrahedralizationCompleted;

    [RequiredByNativeCode]
    private static void Internal_CallTetrahedralizationCompletedFunction()
    {
      if (LightProbes.tetrahedralizationCompleted == null)
        return;
      LightProbes.tetrahedralizationCompleted();
    }

    public static event Action needsRetetrahedralization;

    [RequiredByNativeCode]
    private static void Internal_CallNeedsRetetrahedralizationFunction()
    {
      if (LightProbes.needsRetetrahedralization == null)
        return;
      LightProbes.needsRetetrahedralization();
    }

    /// <summary>
    ///   <para>Synchronously tetrahedralize the currently loaded LightProbe positions.</para>
    /// </summary>
    [FreeFunction]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void Tetrahedralize();

    /// <summary>
    ///   <para>Asynchronously tetrahedralize all currently loaded LightProbe positions.</para>
    /// </summary>
    [FreeFunction]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void TetrahedralizeAsync();

    [FreeFunction]
    public static void GetInterpolatedProbe(
      Vector3 position,
      Renderer renderer,
      out SphericalHarmonicsL2 probe)
    {
      LightProbes.GetInterpolatedProbe_Injected(ref position, renderer, out probe);
    }

    [FreeFunction]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern bool AreLightProbesAllowed(Renderer renderer);

    /// <summary>
    ///   <para>Calculate light probes and occlusion probes at the given world space positions.</para>
    /// </summary>
    /// <param name="positions">The array of world space positions used to evaluate the probes.</param>
    /// <param name="lightProbes">The array where the resulting light probes are written to.</param>
    /// <param name="occlusionProbes">The array where the resulting occlusion probes are written to.</param>
    public static void CalculateInterpolatedLightAndOcclusionProbes(
      Vector3[] positions,
      SphericalHarmonicsL2[] lightProbes,
      Vector4[] occlusionProbes)
    {
      if (positions == null)
        throw new ArgumentNullException(nameof (positions));
      if (lightProbes == null && occlusionProbes == null)
        throw new ArgumentException("Argument lightProbes and occlusionProbes cannot both be null.");
      if (lightProbes != null && lightProbes.Length < positions.Length)
        throw new ArgumentException(nameof (lightProbes), "Argument lightProbes has less elements than positions");
      if (occlusionProbes != null && occlusionProbes.Length < positions.Length)
        throw new ArgumentException(nameof (occlusionProbes), "Argument occlusionProbes has less elements than positions");
      LightProbes.CalculateInterpolatedLightAndOcclusionProbes_Internal(positions, positions.Length, lightProbes, occlusionProbes);
    }

    public static void CalculateInterpolatedLightAndOcclusionProbes(
      List<Vector3> positions,
      List<SphericalHarmonicsL2> lightProbes,
      List<Vector4> occlusionProbes)
    {
      if (positions == null)
        throw new ArgumentNullException(nameof (positions));
      if (lightProbes == null && occlusionProbes == null)
        throw new ArgumentException("Argument lightProbes and occlusionProbes cannot both be null.");
      if (lightProbes != null)
      {
        if (lightProbes.Capacity < positions.Count)
          lightProbes.Capacity = positions.Count;
        if (lightProbes.Count < positions.Count)
          NoAllocHelpers.ResizeList<SphericalHarmonicsL2>(lightProbes, positions.Count);
      }
      if (occlusionProbes != null)
      {
        if (occlusionProbes.Capacity < positions.Count)
          occlusionProbes.Capacity = positions.Count;
        if (occlusionProbes.Count < positions.Count)
          NoAllocHelpers.ResizeList<Vector4>(occlusionProbes, positions.Count);
      }
      LightProbes.CalculateInterpolatedLightAndOcclusionProbes_Internal(NoAllocHelpers.ExtractArrayFromListT<Vector3>(positions), positions.Count, NoAllocHelpers.ExtractArrayFromListT<SphericalHarmonicsL2>(lightProbes), NoAllocHelpers.ExtractArrayFromListT<Vector4>(occlusionProbes));
    }

    [NativeName("CalculateInterpolatedLightAndOcclusionProbes")]
    [FreeFunction]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern void CalculateInterpolatedLightAndOcclusionProbes_Internal(
      [Unmarshalled] Vector3[] positions,
      int positionsCount,
      [Unmarshalled] SphericalHarmonicsL2[] lightProbes,
      [Unmarshalled] Vector4[] occlusionProbes);

    /// <summary>
    ///   <para>Positions of the baked light probes (Read Only).</para>
    /// </summary>
    public extern Vector3[] positions { [NativeName("GetLightProbePositions"), FreeFunction(HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Coefficients of baked light probes.</para>
    /// </summary>
    public extern SphericalHarmonicsL2[] bakedProbes { [FreeFunction(HasExplicitThis = true), NativeName("GetBakedCoefficients"), MethodImpl(MethodImplOptions.InternalCall)] get; [FreeFunction(HasExplicitThis = true), NativeName("SetBakedCoefficients"), MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The number of light probes (Read Only).</para>
    /// </summary>
    public extern int count { [NativeName("GetLightProbeCount"), FreeFunction(HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The number of cells space is divided into (Read Only).</para>
    /// </summary>
    public extern int cellCount { [NativeName("GetTetrahedraSize"), FreeFunction(HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; }

    [FreeFunction]
    [NativeName("GetLightProbeCount")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern int GetCount();

    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Use GetInterpolatedProbe instead.", true)]
    public void GetInterpolatedLightProbe(
      Vector3 position,
      Renderer renderer,
      float[] coefficients)
    {
    }

    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Use bakedProbes instead.", true)]
    public float[] coefficients
    {
      get => new float[0];
      set
      {
      }
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetInterpolatedProbe_Injected(
      ref Vector3 position,
      Renderer renderer,
      out SphericalHarmonicsL2 probe);
  }
}
